package orderCus;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import common.Customer;

public class PassUpdateServlet extends HttpServlet {

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		String pass = req.getParameter("pass");
		HttpSession session = req.getSession();
		Customer user = (Customer)session.getAttribute("user");
		String code = user.getCode();
		String msg = null;
		
		if(pass == null || pass.length() == 0){
			msg = "ご入力内容に誤りがあります。";
		}
		//半角英数以外は処理せずにエラーメッセージを出す
		if(!pass.matches("[0-9a-zA-Z]+")){
			msg = "ご入力内容に誤りがあります。";
		}
		
		if(msg == null || msg.length() == 0){
			Customer.change_pass(pass, code);
			msg = "ご変更を受け付けました。";
		}
		req.setAttribute("msg", msg);
		RequestDispatcher rd = req.getRequestDispatcher("../customer/passChange.jsp");
		rd.forward(req, resp);
		
	}
	
}
